﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject.Web.Mvc;
using Ninject;
using Meraz.Core.Config;
using Spark.Web.Mvc;
using Meraz.Core.Factories;
namespace Meraz.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    //URL Routing help: http://stackoverflow.com/questions/2246481/routing-with-multiple-parameters-using-asp-net-mvc

    public class MvcApplication : NinjectHttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.Clear();
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("favicon.ico");
            routes.IgnoreRoute("images/*");


            routes.MapRoute(
                "TwitterStudy", // Route name
                "Twitter/Study/{studyID}/{username}", // URL with parameters
                new { controller = "Twitter", action = "Study", studyID = UrlParameter.Optional, username = UrlParameter.Optional }
            );

            routes.MapRoute(
                "AddTwitterUser", // Route name
                "Twitter/AddUser/{username}/{studyID}", // URL with parameters
                new { controller = "Twitter", action = "AddUser", studyID = UrlParameter.Optional } // Parameter defaults
            );

            routes.MapRoute(
                "AddTwitterUserToStudy", // Route name
                "TwitterStudy/AddUser/{studyID}/{username}", // URL with parameters
                new { controller = "TwitterStudy", action = "AddUser" } // Parameter defaults
            );

            routes.MapRoute(
                "RemoveTwitterUser", // Route name
                "Twitter/RemoveUser/{username}/{studyID}", // URL with parameters
                new { controller = "Twitter", action = "RemoveUser" } // Parameter defaults
            );

            routes.MapRoute(
                "RemoveTwitterUserFromStudy", // Route name
                "TwitterStudy/RemoveUser/{studyID}/{username}", // URL with parameters
                new { controller = "TwitterStudy", action = "RemoveUser" } // Parameter defaults
            );

            routes.MapRoute(
                "TwitterUser", // Route name
                "TwitterUser/{username}", // URL with parameters
                new { controller = "TwitterUser", action = "Index" } // Parameter defaults
            );

            routes.MapRoute(
                "FacebookBoard", // Route name
                "Facebook/Board/{id}", // URL with parameters
                new { controller = "Facebook", action = "Board" } // Parameter defaults
            );

            routes.MapRoute(
                "FacebookTopic", // Route name
                "Facebook/Board/{boardid}/{topicid}", // URL with parameters
                new { controller = "Facebook", action = "Topic" } // Parameter defaults
            );

            routes.MapRoute(
                "FacebookTopicSave", // Route name
                "Facebook/Board/SaveTopic", // URL with parameters
                new { controller = "Facebook", action = "SaveTopic" } // Parameter defaults
            );

            routes.MapRoute(
                "FacebookPost", // Route name
                "Facebook/Post/{boardid}/{topicid}/{postid}", // URL with parameters
                new { controller = "Facebook", action = "Post" } // Parameter defaults
            );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

        }
        public override void Init()
        {
            AreaRegistration.RegisterAllAreas();

            ViewEngines.Engines.Add(new SparkViewFactory());

            RegisterRoutes(RouteTable.Routes);
        }

        protected override IKernel CreateKernel()
        {
            IKernel kernel =  new StandardKernel(new LiveModule());
            Application.Add("Factory", kernel.Get<IObjectFactory>());
            return kernel;
        }
    }
}